package com.adtech.sys.birthcertificate.utils;


public class demo {

    static String secretKey = "JeF8U9wHFOMfs2Y8";

    /**
     * 解密
     *
     * @param cipherText
     * @return
     * @throws Exception
     */
    public static String decryptData_ECB(String cipherText) throws Exception {
        SM4Utils sm4 = new SM4Utils();
        sm4.setSecretKey(secretKey);
        sm4.setHexString(false);
        return sm4.decryptData_ECB(cipherText);
    }

    /**
     * 加密
     *
     * @param plainText
     * @return
     */
    public static String encryptData_ECB(String plainText) throws Exception {
        SM4Utils sm4 = new SM4Utils();
        sm4.setSecretKey(secretKey);
        sm4.setHexString(false);
        return sm4.encryptData_ECB(plainText);
    }

    public static void main(String[] args) throws Exception {
        StringBuffer xml = new StringBuffer();
        xml.append("<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\" ?>"
                + "<input><row>"
                + "<nameChild>李思妍</nameChild>"
                + "<dateBrithChild>2013/10/8</dateBrithChild>"
                + "<nameMother>母亲姓名</nameMother>"
                + "<idCardMother>500225198812171941</idCardMother>"
                + "<nameFather>父亲姓名</nameFather>"
                + "<idCardFather>500225198802172211</idCardFather>"
                + "<businessCode>20</businessCode>"
                + "</row></input>");
        String cipherText = encryptData_ECB(xml.toString());
        System.out.println("密文=" + cipherText);

        String plainText = decryptData_ECB(cipherText);
        System.out.println("明文=" + plainText);
    }
}
